package com.dequan.springaiproject.utils;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;



public class SpringAiChatClientUtil {
    public static ChatClient simpleSetChatClient(
            OpenAiApi baseOpenAiApi,
            OpenAiChatModel chatModel
    ) {
        // 设置 API Key 和 Base URL
        OpenAiApi openAiApi = baseOpenAiApi.mutate()
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode")
                .apiKey("sk-f57d7ba62a574c7c9741940491a92897")
                .build();

        // 设置 模型选项
        OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder()
                .model("qwen")
                .temperature(0.7)
                .build();

        // 创建 ChatModel
        OpenAiChatModel openAiChatModel = chatModel.mutate()
                .openAiApi(openAiApi)
                .defaultOptions(openAiChatOptions)
                .build();

        return ChatClient.builder(openAiChatModel).build();
    }
}
